package org.filter4osgi.builder.integration.testing

import org.junit.runner.RunWith
import org.ops4j.pax.exam.junit.JUnit4TestRunner
import org.junit.Test

import org.ops4j.pax.exam.Inject
import org.osgi.framework.BundleContext
import org.ops4j.pax.exam.junit.Configuration
import org.ops4j.pax.exam.Option
import org.junit.Assert;
import static org.filter4osgi.builder.FilterBuilder.*
import static org.ops4j.pax.exam.CoreOptions.*
import org.ops4j.pax.exam.options.CompositeOption

/**
 * Integration test.
 * @author Hamlet D'Arcy
 */
@RunWith (JUnit4TestRunner)
class GroovyIntegrationTest {


    @Inject
    BundleContext bundleContext
//def fooo = new CompositeOption()

    @Configuration
    public Option[] configure() {
        [
                equinox(),
                felix(),
                knopflerfish(),
                provision(
                        bundle(new File('./../out/production/filter4osgi.jar').toURI().toString()),
                        mavenBundle().groupId('org.codehaus.groovy').artifactId('groovy-all').version('1.6.4')
                )
        ] as Option[]
    }


    @Test
    public void test_BundleIsLoaded() {

        def found = bundleContext.bundles.find {
            'filter4osgi' == it.symbolicName
        }
        Assert.assertNotNull('filter4osgi bundle not loaded!', found)
    }

    @Test
    public void test_BundleIsUsable() {
        def result = and(
                eq('mailbox', 'email'),
                eq('lang', 'EN_US')
        ).toString()

        Assert.assertEquals('Wrong filter', '(&(mailbox=email) (lang=EN_US))', result)
    }
}
